package com.witte.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.witte.entity.RespBean;
import com.witte.entity.Service;
import com.witte.service.ServiceService;

@Controller
@ResponseBody
@RequestMapping(value="/api/service")
@CrossOrigin
public class ServiceController {
	@Autowired
	ServiceService service;
	
	@PostMapping("/create")
	public RespBean create(@RequestBody Service s) {
		int rs=service.create(s);
		RespBean respBean=RespBean.error("新加错误！");
		if(rs>0)
			respBean=RespBean.ok("ok");
		return respBean;
	}
	
	@GetMapping("/getStateList")
	public RespBean getStateList(String state,Integer beginPage,Integer pageSize){
		List<Service> list=service.getStateList(state,beginPage,pageSize);
		RespBean respBean=RespBean.error("获取错误！");
		if(list!=null) {
			respBean=RespBean.ok("ok",list);
			respBean.setTotleSize(service.getRecodeCount(state));
		}
		return respBean;
	}
	
	@PostMapping("/allot")
	public RespBean updateAllot(@RequestBody Service s) {
		int rs=service.allot(s);
		RespBean respBean=RespBean.error("指派错误！");
		if(rs>0)
			respBean=RespBean.ok("ok");
		return respBean;
	}
	
	@PostMapping("/dell")
	public RespBean updateDell(@RequestBody Service s) {
		int rs=service.dell(s);
		RespBean respBean=RespBean.error("处理错误！");
		if(rs>0)
			respBean=RespBean.ok("ok");
		return respBean;
	}
	
	@PostMapping("/feedback")
	public RespBean updateFeedback(@RequestBody Service s) {
		int rs=service.feedback(s);
		RespBean respBean=RespBean.error("反馈错误！");
		if(rs>0)
			respBean=RespBean.ok("ok");
		return respBean;
	}
	
	@GetMapping("/search")
	public RespBean updateFeedback(String content) {
		List<Service> list=service.search(content);
		RespBean respBean=RespBean.ok("ok",list);
		return respBean;
	}
}
